package com.LeetCode.why125;

import javax.security.auth.callback.CallbackHandler;

/**
 * Created by Aqc on 2017/8/26.
 */
public class ValidPalindrome {

    public static void main(String str[]) {

        String s = "!ma:m ";
        if (isPalindrome(s)) {
            System.out.println("true!");
        } else {
            System.out.println("false!");
        }

    }

    private static boolean isPalindrome(String s) {
        s = s.trim();
        int len = s.length();
        int front = 0;
        int back = len - 1;
        while (front < back) {
            char begin = s.charAt(front);
            if (Character.isLetterOrDigit(begin)) {//(begin >= 0x61 && begin <= 0x7a)||(begin >= 0x41 && begin <= 0x5a)
                begin = Character.toLowerCase(begin);
            } else {
                front++;
                continue;
            }

            char end = s.charAt(back);
            if (Character.isLetterOrDigit(end)) {//(end >= 0x61 && end <= 0x7a)||(end >= 0x41 && end <= 0x5a)
                end = Character.toLowerCase(end);
            } else {
                back--;
                continue;
            }

            if (begin == end) {
                front++;
                back--;
            } else {
                return false;
            }
        }
        return true;
    }
}
